
<template>
    <div>
        <Row>
            <Col span="4"><h1>提现申请列表</h1></Col>
            <Col span="13"><Button type="primary" size="large" @click="exportData"><Icon type="ios-download-outline"></Icon>导出表格数据</Button></Col> 
            <Col span="1"><Button type="primary" size="large" @click="totalClick1">全部</Button></Col>
            <Col span="6">
                <Input v-model="search1">
                    <Select v-model="select1" slot="prepend" style="width: 80px">
                        <Option value="name">姓名</Option>
                        <Option value="uid">编号</Option>
                        <Option value="p_num">手机号</Option>
                    </Select>
                    <Button slot="append" icon="ios-search" @click="findOne1"></Button>
                </Input>
            </Col>   
        </Row>  
        <Table :columns="columns1" :data="data1" ref="table"></Table>
        <div style="margin: 10px;overflow: hidden">
            <div style="float: right;">
                <Page :total="dataCount1" :page-size="pageSize" show-total @on-change="changePage1"></Page>
            </div>
        </div>
        <Row>
            <Col span="17"><h1>提现成功列表</h1></Col>
            <Col span="1"><Button type="primary" size="large" @click="totalClick2">全部</Button></Col>
            <Col span="6">
                <Input v-model="search2">
                    <Select v-model="select2" slot="prepend" style="width: 80px">
                        <Option value="name">姓名</Option>
                        <Option value="uid">编号</Option>
                        <Option value="p_num">手机号</Option>
                    </Select>
                    <Button slot="append" icon="ios-search" @click="findOne2"></Button>
                </Input>
            </Col>   
        </Row>  
        <Table :columns="columns2" :data="data2"></Table>
        <div style="margin: 10px;overflow: hidden">
            <div style="float: right;">
                <Page :total="dataCount2" :page-size="pageSize" show-total @on-change="changePage2"></Page>
            </div>
        </div>
        <Row>
            <Col span="17"><h1>拒绝提现名单</h1></Col>
            <Col span="1"><Button type="primary" size="large" @click="totalClick3">全部</Button></Col>
            <Col span="6">
                <Input v-model="search3">
                    <Select v-model="select3" slot="prepend" style="width: 80px">
                        <Option value="name">姓名</Option>
                        <Option value="uid">编号</Option>
                        <Option value="p_num">手机号</Option>
                    </Select>
                    <Button slot="append" icon="ios-search" @click="findOne3"></Button>
                </Input>
            </Col>   
        </Row>  
        <Table :columns="columns3" :data="data3"></Table>
        <div style="margin: 10px;overflow: hidden">
            <div style="float: right;">
                <Page :total="dataCount3" :page-size="pageSize" show-total @on-change="changePage3"></Page>
            </div>
        </div>
        <Modal
            v-model="modal1"
            title="审核信息"
            @on-ok="ok">
            <Span>审核通过</Span>
        </Modal> 
        <Modal
            v-model="modal2"
            title="审核信息"
            @on-ok="ok">
            <Span>审核不通过</Span>
        </Modal>
    </div>
</template>
<script>
export default {
    data() {
        return {
            modal1:false,
            modal2:false,
            index:0,
            p:true,
            pageSize:10,
            dataCount1:0,
            select1:"name",
            search1:"",
            historyDate1:[],
            dataCount2:0,
            select2:"name",
            search2:"",
            historyDate2:[],
            dataCount3:0,
            select3:"name",
            search3:"",
            historyDate3:[],
            columns1: [
                {
                    title: "申请人",
                    key: "name"
                },
                {
                    title: "手机号",
                    key: "p_num"
                },
                {
                    title: "开户行",
                    key: "bank"
                },
                {
                    title: "银行卡号",
                    key: "b_num"
                },
                {
                    title: "申请时间",
                    key: "create_time",
                    render:(h,params)=>{
                        return h('div', function(){
                            let n = Date.parse(params.row.create_time);
                            let date = new Date();
                            date.setTime(n);
                            return date.toLocaleString();
                        }())
                    }
                },
                {
                    title: "提现金额",
                    key: "price"
                },
                {
                    title: "审批",
                    key: "action",
                    width: 150,
                    align: "center",
                    render: (h, params) => {
                        return h("div", [
                            h(
                                "Button",
                                {
                                    props: {
                                        type: "primary",
                                        size: "small"
                                    },
                                    on: {
                                        click: () => {
                                            this.pass(params.index);
                                        }
                                    }
                                },
                                "通过"
                            ),
                             h(
                                "Button",
                                {
                                    props: {
                                        type: "error",
                                        size: "small"
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index);
                                        }
                                    }
                                },
                                "拒绝"
                            )
                        ]);
                    }
                }
            ],
               columns2: [
                {
                    title: "申请人",
                    key: "name"
                },
                {
                    title: "申请时间",
                    key: "create_time",
                    render:(h,params)=>{
                        return h('div', function(){
                            let n = Date.parse(params.row.create_time);
                            let date = new Date();
                            date.setTime(n);
                            return date.toLocaleString();
                        }())
                    }
                },
                 {
                    title: "提现金额",
                    key: "price"
                }, 
                {
                    title: "审批时间",
                    key: "auditing_time",
                    render:(h,params)=>{
                        return h('div', function(){
                            let n = Date.parse(params.row.auditing_time);
                            let date = new Date();
                            date.setTime(n);
                            return date.toLocaleString();
                        }())
                    }
                },
                  {
                    title: "审批人",
                    key: "cname"
                },
               ],
               columns3: [
                {
                    title: "申请人",
                    key: "name"
                },
                {
                    title: "申请时间",
                    key: "create_time",
                    render:(h,params)=>{
                        return h('div', function(){
                            let n = Date.parse(params.row.create_time);
                            let date = new Date();
                            date.setTime(n);
                            return date.toLocaleString();
                        }())
                    }
                },
                 {
                    title: "提现金额",
                    key: "price"
                }, 
                {
                    title: "审批时间",
                    key: "auditing_time",
                    render:(h,params)=>{
                        return h('div', function(){
                            let n = Date.parse(params.row.auditing_time);
                            let date = new Date();
                            date.setTime(n);
                            return date.toLocaleString();
                        }())
                    }
                },
                  {
                    title: "审批人",
                    key: "cname"
                },
               ],
            data1: [
                
            ],
            data2:[
                
            ],
            data3:[
                
            ]
        };
    },
    mounted() {
        let mid = localStorage.getItem("mid");
        if (mid == 'undefined' || mid == ''){
            alert("您还没有登陆");
            this.$router.push("admin");
            return;
        }
        if (mid.indexOf('4') < 0){
            alert("您没有权限");
            return;
        }
        this.getService1();
        this.getService2();
        this.getService3();
    },
    methods: {
        totalClick1(){
            this.getService1();
        },
        changePage1(index){
            let start = (index - 1) * this.pageSize;
            let end = index * this.pageSize;
            this.data1 = this.historyDate1.slice(start, end);
        },
        findOne1(){
            let data = {};
            switch(this.select1){
                case "name":
                    data["id"] = "name";                   
                break;
                case "uid":
                    data["id"] = "uid";
                break;
                case "p_num":
                    data["id"] = "p_num";
                break;
            }
            data["value"] = this.search1;
            let qs = require('qs');
            this.axios({
                method: "post",
                url: `${this.adminUrl}/getCashedListByOne`,
                data: qs.stringify({id:data["id"], value:data["value"]})
                }).then(response => {
                    if ((response.data.result == 200)) {
                        this.historyDate1 = response.data.data;
                        this.dataCount1 = this.historyDate1.length;
                        if (this.historyDate1.length <= this.pageSize){
                            this.data1 = this.historyDate1;
                        }else{
                            this.data1 = this.historyDate1.slice(0, this.pageSize);
                        }
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            });
        },      
        getService1(){
            let qs = require('qs');
            this.axios({
                method: "post",
                url: `${this.adminUrl}/getCashedList`,
                data: qs.stringify({})
                }).then(response => {
                    if ((response.data.result == 200)) {
                        this.historyDate1 = response.data.data;
                        this.dataCount1 = this.historyDate1.length;
                        if (this.historyDate1.length <= this.pageSize){
                            this.data1 = this.historyDate1;
                        }else{
                            this.data1 = this.historyDate1.slice(0, this.pageSize);
                        }
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            });
        },   
        totalClick2(){
            this.getService2();
        },
        changePage2(index){
            let start = (index - 1) * this.pageSize;
            let end = index * this.pageSize;
            this.data2 = this.historyDate2.slice(start, end);
        },
        findOne2(){
            let data = {};
            switch(this.select2){
                case "name":
                    data["id"] = "name";                   
                break;
                case "uid":
                    data["id"] = "uid";
                break;
                case "p_num":
                    data["id"] = "p_num";
                break;
            }
            data["value"] = this.search2;
            let qs = require('qs');
            this.axios({
                method: "post",
                url: `${this.adminUrl}/getSuccessCashedByOne`,
                data: qs.stringify({id:data["id"], value:data["value"]})
                }).then(response => {
                    if ((response.data.result == 200)) {
                        this.historyDate2 = response.data.data;
                        this.dataCount2 = this.historyDate2.length;
                        if (this.historyDate2.length <= this.pageSize){
                            this.data2 = this.historyDate2;
                        }else{
                            this.data2 = this.historyDate2.slice(0, this.pageSize);
                        }
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            });
        },       
        getService2(){
            let qs = require('qs');
            this.axios({
                method: "post",
                url: `${this.adminUrl}/getSuccessCashed`,
                data: qs.stringify({})
                }).then(response => {
                    if ((response.data.result == 200)) {
                        this.historyDate2 = response.data.data;
                        this.dataCount2 = this.historyDate2.length;
                        if (this.historyDate2.length <= this.pageSize){
                            this.data2 = this.historyDate2;
                        }else{
                            this.data2 = this.historyDate2.slice(0, this.pageSize);
                        }
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            });
        },
        totalClick3(){
            this.getService3();
        },
        changePage3(index){
            let start = (index - 1) * this.pageSize;
            let end = index * this.pageSize;
            this.data3 = this.historyDate3.slice(start, end);
        },
        findOne3(){
            let data = {};
            switch(this.select3){
                case "name":
                    data["id"] = "name";                   
                break;
                case "uid":
                    data["id"] = "uid";
                break;
                case "p_num":
                    data["id"] = "p_num";
                break;
            }
            data["value"] = this.search3;
            let qs = require('qs');
            this.axios({
                method: "post",
                url: `${this.adminUrl}/getFailCashedByOne`,
                data: qs.stringify({id:data["id"], value:data["value"]})
                }).then(response => {
                    if ((response.data.result == 200)) {
                        this.historyDate3 = response.data.data;
                        this.dataCount3 = this.historyDate3.length;
                        if (this.historyDate3.length <= this.pageSize){
                            this.data3 = this.historyDate3;
                        }else{
                            this.data3 = this.historyDate3.slice(0, this.pageSize);
                        }
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            });
        },        
        getService3(){
            let qs = require('qs');
            this.axios({
                method: "post",
                url: `${this.adminUrl}/getFailCashed`,
                data: qs.stringify({})
                }).then(response => {
                    if ((response.data.result == 200)) {
                        this.historyDate3 = response.data.data;
                        this.dataCount3 = this.historyDate3.length;
                        if (this.historyDate3.length <= this.pageSize){
                            this.data3 = this.historyDate3;
                        }else{
                            this.data3 = this.historyDate3.slice(0, this.pageSize);
                        }
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            });
        },      
        pass(index){
            this.index = index;
            this.modal1 = true;
            this.p = true;
        },        
        remove(index){
            this.index = index;
            this.modal2 = true;
            this.p = false;
        },
        ok(){
            if (p) {
                let qs = require('qs');
                this.axios({
                    method: "post",
                    url: `${this.adminUrl}/updateCashed`,
                    data: qs.stringify(
                        {id:`${this.data1[this.index].id}`, status:0, aid:localStorage.getItem("aid")}
                        )
                    }).then(response => {
                        if ((response.data.result == 200)) {
                            // this.data2 = response.data.data;
                            this.data1.splice(this.index, 1);
                        }else{
                            alert("请求失败");
                        }
                    }).catch(err =>{
                        console.log(err);
                });
            }else{
                let qs = require('qs');
                this.axios({
                    method: "post",
                    url: `${this.adminUrl}/updateCashed`,
                    data: qs.stringify(
                        {id:`${this.data1[this.index].id}`, status:1, aid:localStorage.getItem("aid")}
                        )
                    }).then(response => {
                        if ((response.data.result == 200)) {
                            // this.data2 = response.data.data;
                            this.data1.splice(this.index, 1);
                        }else{
                            alert("请求失败");
                        }
                    }).catch(err =>{
                        console.log(err);
                });
            }                        
        },
        exportData(){
            this.$refs.table.exportCsv({
                filename: '提现申请',
                columns:this.columns1,
                data:this.historyDate1                          
            });
        },
    }
};
</script>

   



<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1{
    margin: 20px 0px;
}
</style>
